package com.qianbei.user;

import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.qianbei.R;
import com.qianbei.bean.ChangeStationBean;
import com.qianbei.bean.LighterRouerBean;
import com.qianbei.bean.Pwdbean;
import com.qianbei.bean.RequeastBean1;
import com.qianbei.common.base.BaseActivity;
import com.qianbei.common.base.Basebean;
import com.qianbei.common.base.MyApplication;
import com.qianbei.common.init.SetData;
import com.qianbei.common.net.control.ServerControl;
import com.qianbei.common.net.control.ServerResult;
import com.qianbei.common.net.okhttp.RequeastBean;
import com.qianbei.common.net.view.MsgAlert;
import com.qianbei.common.net.view.ProgressDialog;
import com.qianbei.common.utilis.Util;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Dylan
 */

public class ChangePwdActivity extends BaseActivity {
    @Bind(R.id.old_pwd)
    EditText old_pwd;
    @Bind(R.id.new_pwd)
    EditText new_pwd;
    @Bind(R.id.new_pwd_sure)
    EditText new_pwd_sure;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_modify_pwd);
        ButterKnife.bind(this);
        setTitle("修改密码");
    }

    @OnClick(R.id.change_bt)
    public void oViewClicked() {
        String oldPwd = old_pwd.getText().toString();
        if (!SetData.getPSW().equals(oldPwd)) {
            Util.show(this, "旧密码不正确哦");
            return;
        }
        String newPwd = new_pwd.getText().toString();
        String newPwdSure = new_pwd_sure.getText().toString();
        if (TextUtils.isEmpty(newPwd)) {
            Util.show(this, "新密码不能为空哦");
            return;
        }
        if (!newPwd.equals(newPwdSure)) {
            Util.show(this, "两次输入的新密码不一致哦");
            return;
        }

        Pwdbean serviceBody = new Pwdbean();
        serviceBody._id = SetData.getUserID();
        serviceBody.username = SetData.getUSER();
        serviceBody.oldOnePassword = oldPwd;
        serviceBody.password = newPwd;
        RequeastBean1 bean = new RequeastBean1("updateCustomerAccountById",
                "com.cygps.dubbo.WasteTransport.ICustomerAccount",
                serviceBody, "WT_Account");
        ServerControl sc = new ServerControl(bean);
        sc.serverListener = new ServerControl.ServerListener() {
            @Override
            public void serverFinish(ServerResult sr) {
                Log.d("修改密码", "返回:"   + sr.toString());
                if (sr.isContinue) {
                    //修改成功,去登录
                    SetData.setUserID("");
                    Util.show(ChangePwdActivity.this, "密码修改成功,请重新登录");
                    finish();
                } else {
                    Util.show(getBaseContext(),"修改失败,请稍后重试");
                }
            }
        };
        new ProgressDialog(mContext).OKpost1(sc, "加载中...");

    }
}
